#!/usr/bin/perl 
use DBI;
use CGI;
use TTraker;
use strict;

my $dbh;
initialize_dbi();
print_header();

my $form_ref = parse_input();
my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $cliId = $FORM_DATA{'cliID'};

# convert cli id to Upper Case without spaces
$cliId =~ tr/a-z/A-Z/;
$cliId =~ s/^\s*//;
$cliId =~ s/$\s*//;
$cliId =~ s/\s+//g;

if ($cliId eq "") {
	my $msg = "NO CLIENT ID ENTERED";
    log_in_screen_from_pm ($msg);
} else {
	modify_client ($num,$name,$job,$loc,$cliId);
}	

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################


sub modify_client
{
	my $num = $_[0];
	my $name = $_[1];
	my $job = $_[2];
	my $loc = $_[3];
	my $cliId = $_[4];
	my $cliInfo = get_client_info ($cliId);
	my ($cliID, $facility, $client_name, $category, $active) = @$cliInfo;
#  print "$cliID, $facility, $client_name, $category, $active<br/>";
	
print <<ENDHEADER;
  <html>
  <head>
  <link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
  <script type='text/javascript' src='${js_ref}trak.js'></script>
  <title>trak_03_adm_add_new_client.pl</title>
  </head>
  <body>
  <h2><center>${banner}</center></h2>
  <hr/>
  &nbsp&nbsp&nbsp&nbsp&nbsp
  <div id = "box5_1"> 
  <h3>Update Client Information</h3>
  </div>
<form id="box2_0" autocomplete="off" name="empID" action="${cgi_ref}trak_04_adm_update_client_data.pl" method="post">
  <input type="hidden" name="empNum" value='$num'/>
  <input type="hidden" name="empName" value='$name'/>
  <input type="hidden" name=empJob value='$job'/>
  <input type="hidden" name=empLoc value='$loc'/>
<input type="hidden" name="cliId" value='$cliId'/>
  <table>
	<tr>
  		<td>Client ID:<td/>
		<td id="warn">$cliId<td/> 
	<tr/>
	<tr>
  		<td>Facility #:<td/>
  		<td><input type="text" size=2 value= "$facility" name=cliFac /><td/>
  	<tr/>
  	<tr>
  		<td>Name:<td/>
  		<td><input type="text" size=30 value="$client_name" name=cliName /><td/>
	<tr/>
	<tr>	
  		<td>Revenue Code: &nbsp&nbsp<td/>
  		<td><input type="text" size=2 value="$category" name=cliCat /><td/>
	<tr/>
	<tr>	
  		<td>Active:<td/>
  		<td><input type="text" size=2 value="$active" name=cliAct /><td/>
	<tr/>
	<table/>
   <br/><br/><br/>
   <input type="submit" value="Update Information">
   <br/><br/><br/>
   <a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
   <br/><br/>
 </form>
 </div>
 </body>
 </html>
ENDHEADER
}


